const Koa = require('koa');
const router  = require('koa-router')();
const views = require('koa-views');
const app = new Koa();
/* 配置中间件 */
app.use(views('views',{
    extension:'ejs'
}))
/* 用这个中间件配置公共数据,让所有的ejs模块共享*/
app.use(async (ctx,next)=>{
    ctx.state = {
        userInfo:"ejs公共信息"
    }
    await next()
})
router.get('/',async ctx=>{
    var title =["HTML","css","Javascript"]
    await ctx.render('index',{title,isShow:true})
})
router.get('/detail',async ctx=>{
    var detail ="这是详情页";
    await ctx.render('detail',{detail})
})
app.use(router.routes()).use(router.allowedMethods())
app.listen(8080)